package cn.lanqiao.springboot.util;

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = "emailQueue")
public class RabbitConsumer {

    @Autowired
    EmailSenderUtil emailSenderUtil;

    /**
     * 消息消费
     *
     * @RabbitHandler 代表此方法为接受到消息后的处理方法
     */
    @RabbitHandler
    public void received(String msg) {
        System.out.println("消费者收到消息  : " + msg);
        emailSenderUtil.sendEmail(msg);
    }

}
